package com.example.hasee.zhcd.Adapters;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.hasee.zhcd.Activities.ChuanWu.LPEntrustActivity;
import com.example.hasee.zhcd.Activities.ChuanWu.LPInnerActivity;
import com.example.hasee.zhcd.R;
import com.example.hasee.zhcd.Util.GlobalParameter;

import java.util.ArrayList;
import java.util.HashMap;

import static com.example.hasee.zhcd.R.id.fmje;


/**
 * Created by hasee on 2017/9/13.
 */

public class DlfsrAdapter extends BaseAdapter {
    private HashMap<String, String> map = (HashMap<String, String>) GlobalParameter.get("loginmap");
    private ArrayList<HashMap<String, String>> list;
    private LayoutInflater itemInflater;
    private Context context;
    private Holder holder;

    public DlfsrAdapter(Context context, ArrayList<HashMap<String, String>> list) {
        this.context = context;
        this.list = list;
        this.itemInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            holder = new Holder();
            convertView = itemInflater.inflate(R.layout.dlfsr_list_item, null);
            holder.fcgs = (TextView) convertView.findViewById(R.id.fcgs);
            holder.fmsc = (TextView) convertView.findViewById(R.id.fmsc);
            holder.fmton = (TextView) convertView.findViewById(R.id.fmton);
            holder.fmje = (TextView) convertView.findViewById(fmje);
            holder.fsumm = (TextView) convertView.findViewById(R.id.fsumm);
            holder.fysc = (TextView) convertView.findViewById(R.id.fysc);
            holder.fyton = (TextView) convertView.findViewById(R.id.fyton);
            holder.fyje = (TextView) convertView.findViewById(R.id.fyje);
            holder.fsumy = (TextView) convertView.findViewById(R.id.fsumy);
            holder.fzsc = (TextView) convertView.findViewById(R.id.fzsc);
            holder.fzton = (TextView) convertView.findViewById(R.id.fzton);
            holder.fzje = (TextView) convertView.findViewById(R.id.fzje);
            holder.fsumz = (TextView) convertView.findViewById(R.id.fsumz);
            holder.m_linear = (LinearLayout) convertView.findViewById(R.id.m_linear);
            holder.y_linear = (LinearLayout) convertView.findViewById(R.id.y_linear);
            holder.z_linear = (LinearLayout) convertView.findViewById(R.id.z_linear);
            holder.m_line = (View) convertView.findViewById(R.id.m_line);
            holder.y_line = (View) convertView.findViewById(R.id.y_line);
            holder.z_line = (View) convertView.findViewById(R.id.z_line);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        holder.fcgs.setText((String) list.get(position).get("fcgs"));
        //煤
        if (list.get(position).get("fmsc").trim().length() == 0) {
            holder.m_linear.setVisibility(View.GONE);
            holder.m_line.setVisibility(View.GONE);
        } else {
            holder.m_linear.setVisibility(View.VISIBLE);
            holder.m_line.setVisibility(View.VISIBLE);
            holder.fmsc.setText(list.get(position).get("fmsc"));
            holder.fmton.setText(list.get(position).get("fmton"));
            holder.fmje.setText(list.get(position).get("fmje"));
            holder.fsumm.setText(list.get(position).get("fsumm"));
        }
        //油
        if (list.get(position).get("fysc").trim().length() == 0) {
            holder.y_linear.setVisibility(View.GONE);
            holder.y_line.setVisibility(View.GONE);
        } else {
            holder.y_linear.setVisibility(View.VISIBLE);
            holder.y_line.setVisibility(View.VISIBLE);
            holder.fysc.setText(list.get(position).get("fysc"));
            holder.fyton.setText(list.get(position).get("fyton"));
            holder.fyje.setText(list.get(position).get("fyje"));
            holder.fsumy.setText(list.get(position).get("fsumy"));
        }
        //杂
        if (list.get(position).get("fzsc").trim().length() == 0) {
            holder.z_linear.setVisibility(View.GONE);
            holder.z_line.setVisibility(View.GONE);
        } else {
            holder.z_linear.setVisibility(View.VISIBLE);
            holder.z_line.setVisibility(View.VISIBLE);
            holder.fzsc.setText(list.get(position).get("fzsc"));
            holder.fzton.setText(list.get(position).get("fzton"));
            holder.fzje.setText(list.get(position).get("fzje"));
            holder.fsumz.setText(list.get(position).get("fsumz"));
        }
        return convertView;
    }

    class Holder {
        private TextView fcgs;
        private TextView fmsc;
        private TextView fmton;
        private TextView fmje;
        private TextView fsumm;
        private TextView fysc;
        private TextView fyton;
        private TextView fyje;
        private TextView fsumy;
        private TextView fzsc;
        private TextView fzton;
        private TextView fzje;
        private TextView fsumz;
        private LinearLayout m_linear;
        private LinearLayout y_linear;
        private LinearLayout z_linear;
        private View m_line;
        private View y_line;
        private View z_line;

    }
}
